package git.matrix.service.impl;

import java.util.List;

import javax.annotation.Resource;

import git.matrix.mapper.ProviderMapper;
import git.matrix.pojo.Provider;
import git.matrix.service.BillServices;
import git.matrix.service.ProviderServices;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;



/**
 * 服务层
 * @author admin
 *
 */
@Service
@Transactional//  自动扫描   ---正常--提交；   异常---回滚事物
public class ProviderServicesImpl implements ProviderServices {

	@Autowired
    ProviderMapper mapper;
	@Autowired
    BillServices billServices;
//	@Resource(name="sqlSessionFactory")
//	SqlSessionFactory b;
	
	public List<Provider> getProByNameCode(String queryProCode,
                                           String queryProName) {
		// TODO Auto-generated method stub
		//从spring中获取session
//		SqlSession s = b.openSession();
		List<Provider> data = null;
		
//		try {
			data = mapper.getProByNameCode(queryProCode, queryProName);
			
//			s.commit();//事物提交
//			
//			
//		} catch (Exception e) {
//			// TODO: handle exception
//			 s.rollback();//异常时  
//		}finally{
//			
//			//关闭连接
//			
//		}
		//  spring  aop：把公共功能---》spring  aop---注入
		
		return data;
	}

	/**
	 * 通过id删除    true
	 */
	public String proDelete(int proid) {
		// TODO Auto-generated method stub
		// 判断订单----
		//int i = mapper.proDelete(proid);
		if(billServices.getBillByProId(proid).size()==0)
		{
			//调用  mapper  层---数据库
			int i = mapper.proDelete(proid);
			if(i>0)
			{
				return "true";
			}else
			{
				return "false";
				
			}
		}
		return "false";
		
		
	}

}
